<?php
/**
 * Created by PhpStorm.
 * User: qttx
 * Date: 2019/6/2
 * Time: 16:56
 */
namespace app\shop\controller;

use app\shop\model\TaobaoModel;
use app\shop\model\TaobaoTypeModel;

class Taobao extends BaseController
{
    public function __construct()
    {
        parent::__construct();
        $this->taobao = new TaobaoModel();
        $this->taobaotype = new TaobaoTypeModel();
    }
    //商品列表
    public function index()
    {
        $goodsList = $this->taobao->getGoodsList();
        $this->assign('page',$goodsList->render());
        $this->assign('goodsList',$goodsList);
        return view('taobao/index');
    }
    //商品编辑
    public function goodsEdit()
    {
        if(input('post.')){
            $goodsInfo = $this->taobao->goodsEdit();
            if($goodsInfo)
            {
                echo "<script>setTimeout(function(){window.parent.location.reload();},1000);</script>";
                $this->success('修改成功',"taobao/index");
            }else{
                $this->error('修改失败');
            }
        }else{
            $goodsInfo = $this->taobao->goodsEdit();

            $taobaotype = $this->taobaotype->select();
            $goodsInfo['params'] = json_decode($goodsInfo['params'], true);
//            $goodsInfo['params'] = ;
            $this->assign('goodsInfo',$goodsInfo);
            $this->assign('taobaotype',$taobaotype);
            return view('taobao/edit');
        }
    }
    //商品添加
    public function goodsAdd()
    {
        if(input('post.')){
           //dump(input("params/a"));die;
//echo 1611;die;
            $result = $this->taobao->goodsAdd();
            if($result)
            {
                $this->success('添加成功',"taobao/index");
            }else{
                $this->error('添加失败');
            }
        }else{
            $goodsInfo = $this->taobao->goodsAdd();
            $taobaotype = $this->taobaotype->select();
            $this->assign('goodsInfo',$goodsInfo);
            $this->assign('taobaotype',$taobaotype);
            return view('taobao/edit');
        }
    }
    //商品删除
    public function goodsDel()
    {
        $result = $this->taobao->goodsDel();
        return $result;
    }
    //查看商品简介
    public function lookSynopsis()
    {
        $info = $this->taobao->lookSynopsis();
        $this->assign('info',$info);
        return view('taobao/synopsis');
    }
    //查看商品图
    public function lookImg()
    {
        $info = $this->taobao->lookImg();
        $this->assign('info',$info);
        return view('taobao/synopsis');
    }
    //编辑状态
    public function updateStatus()
    {
        $result = $this->taobao->updateStatus();
        return $result;
    }
    //上传图片
    public function uploadImg()
    {
        $res = $this->taobao->uploadImg();
        return $res;
    }
    //删除图片
    public function delImg()
    {
        $res = $this->taobao->delImg();
        return $res;
    }
    //删除图片
    public function delImgs()
    {
        $res = $this->taobao->delImgs();
        return $res;
    }
}